package jp.sourceforge.akjrcp.ui;

import jp.sourceforge.akjrcp.commons.util.FileNameUtils;
import jp.sourceforge.akjrcp.commons.ui.FileDirChoicer2;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Text;
/**
 * moved use commons
 * @deprected 
 * @author aki
 *
 */
public class WidgetBuilder {
	public static Log log = LogFactory.getLog(WidgetBuilder.class);
	public static Group createGridLayoutGroup(Composite parent,int style){
	Group group=new Group(parent,style);
	group.setLayout(new GridLayout());
	return group;
	}
	
	public static Composite createGridLayoutComposite(Composite parent,int style){
		Composite composite=new Composite(parent,style);
		composite.setLayout(new GridLayout());
		return composite;
		}
	
	public static Composite createTwoGridLayoutComposite(Composite parent,int style){
		Composite composite=new Composite(parent,style);
		composite.setLayout(new GridLayout(2,false));
		return composite;
		}
	
	public static Composite createGridLayoutComposite(Composite parent,int style,int num,boolean same){
		Composite composite=new Composite(parent,style);
		composite.setLayout(new GridLayout(num,same));
		return composite;
		}
	public static Button createRadioButton(Composite parent,String label){
		Button bt=new Button(parent,SWT.RADIO);
		bt.setText(label);
		return bt;
	}
	
	public static Button createCheckButton(Composite parent,String label){
		Button bt=new Button(parent,SWT.CHECK);
		bt.setText(label);
		return bt;
	}
	public static Button createButton(Composite parent,String label){
		Button bt=new Button(parent,SWT.NULL);
		bt.setText(label);
		return bt;
	}

	public static Group createFillLayoutGroup(Composite parent, int style) {
		Group group=new Group(parent,style);
		group.setLayout(new FillLayout());
		return group;
	}
	
	public static MenuItem createSeparateMenu(Menu parent){
		return new MenuItem(parent,SWT.SEPARATOR);
	}

	public static Menu createCascadeMenu(Menu parent,String text){
		MenuItem item= new MenuItem(parent,SWT.CASCADE);
		item.setText(text);
		Menu menu=new Menu(item);
		item.setMenu(menu);
		menu.setData("MenuItem",item);
		return menu;
	}
	
	public static MenuItem createPushMenu(Menu parent,String text){
		MenuItem item= new MenuItem(parent,SWT.PUSH);
		item.setText(text);
		return item;
	}
	

	
	public static Text createTextArea(Composite parent,String text){
		Text t=new Text(parent,SWT.MULTI|SWT.BORDER|SWT.V_SCROLL|SWT.H_SCROLL);
		if(text!=null)
			t.setText(text);
		return t;
	}

	public static Text createBorderText(Composite parent,String text){
		Text t=new Text(parent,SWT.BORDER);
		if(text!=null)
			t.setText(text);
		return t;
	}
	
	public static Label createLabel(Composite root, String string) {
		Label label=new Label(root,SWT.NULL);
		label.setText(string);
		return label;
	}
	
	/**
	 * 
	 * @param root
	 * @param style
	 * @param extensions
	 * *.txt
	 * *.txt;*.doc
	 * @return
	 */
	public static EditableFileList createFileList(Composite root, int style,String extensions) {
		EditableFileList fileList=new EditableFileList(root,style);
		fileList.setFilterExtension(extensions);
		return fileList;
	}
	/*
	public static FileDirChoicer2 createDirectoryChoicer(Composite parent,int style,String label,boolean hasReset){
		FileDirChoicer2 choicer=new FileDirChoicer2(parent,style,FileDirChoicer2.DIR,label,hasReset);
		
		return choicer;
	}
	
	public static FileDirChoicer2 createFileChoicer(Composite parent,int style,String label,boolean hasReset){
		FileDirChoicer2 choicer=new FileDirChoicer2(parent,style,FileDirChoicer2.FILE,label,hasReset);
		
		return choicer;
	}*/
	
	public static FileDirChoicer2 createDirectoryChoicerWithMyDesktopAndMyDocuments(Composite parent,int style,String label,boolean hasReset){
		FileDirChoicer2 choicer=new FileDirChoicer2(parent,style,FileDirChoicer2.DIR,label,hasReset);
		choicer.addSelectableFileName(FileNameUtils.LOCAL_NAME_MY_DOCUMENTS);
		choicer.addSelectableFileName(FileNameUtils.LOCAL_NAME_DESKTOP);
		return choicer;
	}
	

	
}
